﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet
{
    class CellPair: Pair<Cell, Cell>
    {
        public CellPair(Cell first, Cell second): base(first, second)
        {
            Contract.Requires(first != null || second != null);   
        }
        public IEnumerable<Border> GetHorizontalBorders()
        {
            if (First == null)
            {
                yield return Second.GetActualBorder(BorderType.TopEdge);
                yield break;
            }
            if (Second == null)
            {
                yield return First.GetActualBorder(BorderType.BottomEdge);
                yield break;
            }
            var b1 = First.GetActualBorder(BorderType.BottomEdge);
            var b2 = Second.GetActualBorder(BorderType.TopEdge);
            if (b1 == null)
                yield return b2;
            else if (b2 == null)
                yield return b1;
            else
            {
                yield return b1;
                yield return b2;
            }

        }

        public IEnumerable<Border> GetVerticalBorders()
        {
            if (First == null)
            {
                yield return Second.GetActualBorder(BorderType.LeftEdge);
                yield break;
            }
            if (Second == null)
            {
                yield return First.GetActualBorder(BorderType.RightEdge);
                yield break;
            }
            var b1 = First.GetActualBorder(BorderType.RightEdge);
            var b2 = Second.GetActualBorder(BorderType.LeftEdge);
            if (b1 == null)
                yield return b2;
            else if (b2 == null)
                yield return b1;
            else
            {
                yield return b1;
                yield return b2;
            }
        }
    }
}